<!doctype html>
<html>

<head>
    <meta charset="utf-8" />
    <title>GIS兵器库</title>

    <script src="config_blog.js"></script>
    <script src="config_demo.js"></script>
    <script src="config_source.js"></script>
    <script src="config_download.js"></script>

    <style>
        html, body {
            width: 100%;
            height: 100%;
            position: relative;
            background: #f5f5f5;
            margin: 0;
            padding: 0;
            min-width: 800px;
        }

        .content {
            position: absolute;
            margin-top: 200px;
            margin-left: calc(50% - 400px);
        }

        .contentTitle {
            width: 800px;
            height: 60px;
            margin-bottom: 50px;
            font-size: 36px;
            font-weight: 1000;
            text-align: center;
        }

        .contentUrl {
            width: 800px;
            height: 60px;
            font-size: 18px;
            font-weight: 500;
            text-align: left;
        }
        #backUrlContent{
            display: none;
        }
        #helfUrl{
            display: none;
        }
        .contentUrl a{
            color: #019BDD;
        }
    </style>

</head>

<body>
    <div class="content">
        <div class="contentTitle">
            <span>微信公众号：GIS兵器库</span>
        </div>
        <div class="contentUrl" id="helfUrl">
            <span>正在跳转到：</span>
            <a id="toUrl" href=""></a>
        </div>
        <div class="contentUrl" id="backUrlContent">
            <span>可能您的所处的网络无法正常访问github，您可以尝试访问下面的 github 镜像地址：</span><br/>
            <span>镜像一：</span><a id="backUpUrl"></a><br/>
            <span>镜像二：</span><a id="backUpUrl2"></a>
        </div>
    </div>
</body>

<script>
    init();
    //初始化
    function init() {
        var urlArg = getUrlArgObject();
        if (urlArg && urlArg.blog) {
            loadUrl(urlArg.blog, blogList)
        } else if (urlArg && urlArg.demo) {
            loadUrl(urlArg.demo, demoList)
        } else if (urlArg && urlArg.source) {
            loadUrl(urlArg.source, sourceList)
        } else if (urlArg && urlArg.download) {
            loadUrl(urlArg.download, downloadList)
        } else {
            // window.location.href = 'https://blog.csdn.net/gisarmory'
            window.location.href = 'http://gisarmory.xyz/blog/main.html'
        }
    }

    function loadUrl(urlId, dataList) {

        for (var i = 0; i < dataList.length; i++) {
            var dataObj = dataList[i];
            if (dataObj.id == urlId) {
                var href = ''
                if (dataObj.href) {
                    href = dataObj.href;
                } else if (dataObj.url) {
                    href = dataObj.url;
                }
                
                //延迟跳转
                setTimeout(function(){
                    window.location.href = href
                }, 800);
                
                //延迟显示提示
                setTimeout(function(){
                    //正在跳转地址
                    document.getElementById('toUrl').innerHTML  = href
                    document.getElementById('toUrl').href  = href
                    document.getElementById('helfUrl').style.display = 'block'
                }, 2000);
                
                //延迟github镜像提示
                setTimeout(function(){
                    var hrefArr = href.split('https://github.com')
                    if(hrefArr.length > 1){
                        //镜像1
                        var backUrl = 'https://github.com.cnpmjs.org' + hrefArr[1]
                        document.getElementById('backUpUrl').innerHTML  = backUrl
                        document.getElementById('backUpUrl').href  = backUrl
                        //镜像2
                        backUrl = 'https://hub.fastgit.org' + hrefArr[1]
                        document.getElementById('backUpUrl2').innerHTML  = backUrl
                        document.getElementById('backUpUrl2').href  = backUrl

                        document.getElementById('backUrlContent').style.display = 'block'
                    }else{
                        document.getElementById('backUrlContent').style.display = 'none'
                    }
                }, 8000);
            }
        }
    }

    //返回的是对象形式的参数
    function getUrlArgObject() {
        var args = new Object();
        var query = location.search.substring(1); //获取查询串
        var pairs = query.split(","); //在逗号处断开
        for (var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('='); //查找name=value
            if (pos == -1) { //如果没有找到就跳过
                continue;
            }
            var argname = pairs[i].substring(0, pos); //提取name
            var value = pairs[i].substring(pos + 1); //提取value
            args[argname] = unescape(value); //存为属性
        }
        return args; //返回对象
    }
</script>

</html>